//单例模式，静态方法中new实例
import { Bullets } from "./bullets";
import {GameEngine} from "./gameEngine"

export class MyPlane {
  el:HTMLDivElement;
  static instanceObj:MyPlane;
  static instance() {
    if(MyPlane.instanceObj==null) {
      MyPlane.instanceObj = new MyPlane;
    }
    return MyPlane.instanceObj;
  }
  constructor() {
    this.el = document.createElement("div");
    this.el.className = "myplane";

    GameEngine.instance().el.appendChild(this.el); 

    let left = GameEngine.instance().el.offsetWidth/2 - this.el.offsetWidth/2;
    this.el.style.left = left + "px";
    let top =GameEngine.instance().el.offsetHeight - this.el.offsetHeight;
    this.el.style.top = top + "px";
  }

  fire() {
    setInterval(()=> {
      new Bullets();
    },500 )
  }
}